<?php

use think\facade\Route;
use think\facade\Request;

$version = Request::header('version', 'v1');
$api ='/';
if(config('url_route_must')){
    Route::domain(config('admin_domain'), function (){
        if(request()->has('s')){
            $s = request()->get('s');
            $s = str_replace('.html','',$s);
            if(substr_count($s,'/') == 1){
                Route::rule('admin/:controller', $s.'/index');
            }else{
                Route::rule('admin/:controller', $s);
            }
        }
        Route::rule(':module/:controller/:function', ':module/:controller/:function');
        Route::rule('admin/:controller', 'admin/:controller/index');
        Route::rule(':controller/:function', 'admin/:controller/:function');
        Route::rule(':module', 'admin/index/index');
        Route::rule('/', 'admin/index/index');
    });
}else{
    $api = 'api/';
}
//商城支付回调
Route::any($api.'shop/Notify/pay',"shop/api.{$version}.notify/pay")->name('shop_notify');
//商城模块API
Route::group($api.'shop/', function () use ($version) {
    Route::controller(':controller',"shop/api.{$version}.:controller")->middleware('auth');
    Route::get('index/region', 'Index/getRegion');
    Route::get('index/school', 'Index/getSchool');
    Route::get('index/banner', 'Index/getBanner');
    Route::get('goods/cate', 'Goods/getCate');
    Route::get('goods/list', 'Goods/getList');
    Route::get('opinion/index', 'Opinion/getIndex');
    Route::get('index/storeInfo', 'Index/getStoreInfo');
    Route::get('index/customer', 'Index/getCustomer');
    Route::get('index/userText', 'Index/getUserText');
    Route::get('index/about', 'Index/getAbout');
    Route::get('index/news', 'Index/getNews');
    Route::get('time/overdue', 'Time/getOverdue');
    Route::get('timeOrder/card', 'TimeOrder/getCard');
    Route::get('timeOrder/del', 'TimeOrder/getDel');
    Route::get('timeOrder/cancel', 'TimeOrder/getCancel');
    Route::get('timeOrder/memberMarketing', 'TimeOrder/memberMarketing');
    Route::get('timeCoupon/expire', 'TimeCoupon/getExpire');
    Route::get('timeCoupon/effect', 'TimeCoupon/getEffect');
    Route::get('index/pay', 'Index/getPay');
})->prefix("shop/api.{$version}.")->middleware(['visit','throttle'])->domain(config('api_domain'))->allowCrossDomain();

//商家端小程序模块API
Route::group($api.'store/', function () use ($version) {
    Route::controller(':controller',"store/api.{$version}.:controller")->middleware('auth');
    // Route::get('index/index', 'Index/getIndex');
    // Route::get('index/platform', 'Index/getPlatform');
})->prefix("store/api.{$version}.")->middleware(['visit','throttle'])->domain(config('api_domain'))->allowCrossDomain();

//通用模块API
Route::group($api, function () use ($version) {
    Route::any('common/:function','Common/:function');
    Route::controller(':controller',"api/{$version}.:controller")->middleware('auth');
})->prefix("api/{$version}.")->middleware(['visit','throttle'])->domain(config('api_domain'))->allowCrossDomain();




